package com.suxin.datahub.database;

import com.suxin.datahub.core.reader.MySqlReader;
import com.suxin.datahub.core.reader.OracleReader;
import com.suxin.datahub.core.reader.Reader;
import com.suxin.datahub.core.writer.MySqlWriter;
import com.suxin.datahub.core.writer.OracleWriter;
import com.suxin.datahub.core.writer.Writer;
import com.suxin.datahub.domain.DataSourceDomain;
import com.suxin.datahub.domain.DataSourceJob;
import com.suxin.datahub.enums.DbType;

/**
 * @Classname ReaderWriterFactory
 * @Description [ TODO ]
 * @Author Tang
 * @Date 2020/11/11 14:14
 * @Created by ASUS
 */
public class ReaderWriterFactory {

    public static Reader getReader(DataSourceJob dataSourceJob) {
        DataSourceDomain readerDataSource = dataSourceJob.getReaderDataSource();
        String name = readerDataSource.getDbType().getName();

        if (DbType.MYSQL.getName().equals(name)) {
            return new MySqlReader(readerDataSource);
        } else if (DbType.ORACLE.getName().equals(name)) {
            return new OracleReader(readerDataSource);
        }
        return null;
    }

    public static Writer getWriter(DataSourceJob dataSourceJob) {
        DataSourceDomain writerDataSource = dataSourceJob.getWriterDataSource();
        String name = writerDataSource.getDbType().getName();

        if (DbType.MYSQL.getName().equals(name)) {
            return new MySqlWriter(writerDataSource);
        } else if (DbType.ORACLE.getName().equals(name)) {
            return new OracleWriter(writerDataSource);
        }
        return null;
    }



}